package com.vonchange.purchase.purchase.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.fasterxml.jackson.core.type.TypeReference;
import com.vonchange.headb.core.map.HeaMap;
import com.vonchange.purchase.purchase.bean.PurchaseLog;
import com.vonchange.purchase.purchase.dao.IPurchaseLogDao;
import com.vonchange.purchase.purchase.service.IPurchaseLogService;
import com.vonchange.utils.crud.dao.IBaseDao;
import com.vonchange.utils.crud.service.normal.impl.BaseServiceImpl;
import com.vonchange.utils.json.JsonUtil;
@Service
@Transactional
public class PurchaseLogServiceImpl extends BaseServiceImpl<PurchaseLog> implements IPurchaseLogService{
	@Resource
    private IPurchaseLogDao purchaseLogDao;
	@Override
	public IBaseDao<PurchaseLog> getDao() {
		// TODO Auto-generated method stub
		return purchaseLogDao;
	}
	
	public void initSave(PurchaseLog entity) {
		entity.setCreateTime(new Date());
	}
	public void initUpdate(PurchaseLog entity) {
		entity.setUpdateTime(new Date());
	}
	 
	public void initFind(HeaMap parameter) {
		if(null==parameter.get("isDelete_eq")){
			parameter.set("isDelete_eq", 0);
		}
	}
	@Override
	public int saveJsonList(String deedId,String logJson) {
		List<PurchaseLog> purchaseLogList=JsonUtil.fromJson(logJson, new TypeReference<List<PurchaseLog>>() {
		});
		//删除原来的deedId
		purchaseLogDao.delete(new HeaMap().set("deedId", deedId));
		for (PurchaseLog purchaseLog : purchaseLogList) {
			save(purchaseLog);
		}
		return 1;
	}
}